﻿using System;
using System.Windows.Forms;

namespace lab03
{
    public partial class Form1 : Form
    {
        private BwWithShadows _bwWithShadows1;
        private BwWithShadows _bwWithShadows2;
        private BwWithoutShadows _bwWithoutShadows1;
        private BwWithoutShadows _bwWithoutShadows2;
        private ColorWithShadows _colorWithShadows1;
        private ColorWithShadows _colorWithShadows2;
        private ColorWithoutShadows _colorWithoutShadows1;
        private ColorWithoutShadows _colorWithoutShadows2;
        private HideMatrixDecorator _denseMatrix;
        private HideMatrixDecorator _sparseMatrix;
        private bool _isDraw;

        private MatrixDrawer _matrixDrawer1;
        private MatrixDrawer _matrixDrawer2;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1Load(object sender, EventArgs e)
        {
            _isDraw = false;

            _colorWithoutShadows1 = new ColorWithoutShadows {Panel = panel1};
            _colorWithoutShadows2 = new ColorWithoutShadows {Panel = panel2};
            _colorWithShadows1 = new ColorWithShadows {Panel = panel1};
            _colorWithShadows2 = new ColorWithShadows {Panel = panel2};
            _bwWithoutShadows1 = new BwWithoutShadows {Panel = panel1};
            _bwWithoutShadows2 = new BwWithoutShadows {Panel = panel2};
            _bwWithShadows1 = new BwWithShadows {Panel = panel1};
            _bwWithShadows2 = new BwWithShadows {Panel = panel2};

            _matrixDrawer1 = _colorWithoutShadows1;
            _matrixDrawer2 = _colorWithoutShadows2;
        }

        private void DrawMe()
        {
            if (!_isDraw) return;
            _denseMatrix.Draw(_matrixDrawer1);
            _sparseMatrix.Draw(_matrixDrawer2);
        }

        private void Button1Click(object sender, EventArgs e)
        {
            //_denseMatrix = new HideMatrixDecorator(new UpperMatrixDecorator(new DenseMatrix(_width, _height)));
            //_sparseMatrix = new HideMatrixDecorator(new UpperMatrixDecorator(new SparseMatrix(_width, _height)));
            _denseMatrix = new HideMatrixDecorator(new DenseMatrix(_width, _height));
            _sparseMatrix = new HideMatrixDecorator(new SparseMatrix(_width, _height));

            MatrixRoutines.Fill(_denseMatrix, 30, 10);

            for (int i = 0; i < _width; i++)
                for (int j = 0; j < _height; j++)
                    _sparseMatrix.SetValue(i, j, _denseMatrix.GetValue(i, j));

            _isDraw = true;
            checkBox1.Checked = false;
            _sparseMatrix.HideOff();
            _denseMatrix.HideOff();

            DrawMe();
        }

        private void RadioButton1CheckedChanged(object sender, EventArgs e)
        {
            _matrixDrawer1 = _colorWithoutShadows1;
            _matrixDrawer2 = _colorWithoutShadows2;
            DrawMe();
        }

        private void RadioButton2CheckedChanged(object sender, EventArgs e)
        {
            _matrixDrawer1 = _colorWithShadows1;
            _matrixDrawer2 = _colorWithShadows2;
            DrawMe();
        }

        private void RadioButton3CheckedChanged(object sender, EventArgs e)
        {
            _matrixDrawer1 = _bwWithoutShadows1;
            _matrixDrawer2 = _bwWithoutShadows2;
            DrawMe();
        }

        private void RadioButton4CheckedChanged(object sender, EventArgs e)
        {
            _matrixDrawer1 = _bwWithShadows1;
            _matrixDrawer2 = _bwWithShadows2;
            DrawMe();
        }

        private void CheckBox1CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox1.Checked)
            {
                _denseMatrix.HideOn();
                _sparseMatrix.HideOn();
            }
            else
            {
                _denseMatrix.HideOff();
                _sparseMatrix.HideOff();
            }
            DrawMe();
        }
    }
}